package Meeting;

import gongju.Communtil;
import gongju.JDBC;
import gongju.User;

import java.util.ArrayList;
import java.util.List;

public class MeetingDAO {
    //属性
    public static final Object[] columnNames = {"会议ID","会议内容","会议地点"};
    public static User getUser(String name){
        String sql = "select * from meeting where content=?";
        List param = new ArrayList();
        param.add(name);
        Object[] obj = JDBC.queryObject(sql, param,3);
        if(obj == null){
            return null;
        }
        User user = new User();
        user.setId((int)obj[0]);
        user.setUsername((String)obj[1]);
        user.setPassword((String)obj[2]);
        user.setType(1);
        return user;
    }

    public static Object[][] searvhMulti(int[] cols,String[] texts){
        String sql = "select id,content from meeting where 1=1";
        List param = new ArrayList();
        if(cols!=null && cols.length>0){
            for(int i=0;i<cols.length;i++){
                if(Communtil.isEmpty(texts[i])){
                    continue;
                }
                switch(cols[i]){
                    case 1:
                        sql += " and content=?";
                        break;
                }
                param.add(texts[i]);
            }
        }
        return Communtil.toArray(JDBC.queryList(sql,param,3));
    }

    public static Object[] findById(Object id){
       String sql = "select * from meeting where id=?";
       List param = new ArrayList();
       param.add(id);
       return JDBC.queryObject(sql,param,3);
    }

    public static void add(Object[] obj){
        String sql = "insert into meeting (id,content,place) values(?,?,?)";
        List param = new ArrayList();
        for (int i = 0; i < obj.length; i++) {
            param.add(obj[i]);
        }
        JDBC.executeUpdate(sql, param);
    }

    public static void remove(Object id){
        String sql = "delete from meeting where id=?";
        List param = new ArrayList();
        param.add(id);
        JDBC.executeUpdate(sql, param);
    }
}
